<template>
  <div>
    <Header>
      <!-- 具名插槽 -->
      <template v-slot:head>
        确认订单
      </template>
      <template v-slot:tip>
        温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算
      </template>
    </Header>
    <Sett :totalPrice="totalPrice" :selectedData="selectedData" @getShopping="getShopping" @getSucceed="getSucceed">
    </Sett>
    <Footer></Footer>
  </div>
</template>

<style scoped></style>
<script>
import Header from '@/components/shoppingBox/header.vue';
import Sett from "@/components/clearingBox/sett.vue";
import Footer from "@/components/indexBox/footer.vue";
export default {
  data() {
    return {
      selectedData: [],
      totalPrice: null
    };
  },
  created() {
    //获取总价格
    this.totalPrice = this.$route.query.totalPrice;
    //商品数据
    this.selectedData = JSON.parse(localStorage.getItem('selectedDate')) || [];
    // console.log(this.totalPrice);
  },
  components: {
    Header,
    Sett,
    Footer
  },
  methods: {
    getShopping() {
      this.$router.push('/shopping');
    },
    getSucceed() {
      // 获取本地存储中已保存的数据
      let storedData = JSON.parse(localStorage.getItem('ordersData')) || [];
      // 将新数据与已保存数据合并
      let newData = storedData.concat(this.selectedData);
      // 保存合并后的数据到本地存储
      localStorage.setItem('ordersData', JSON.stringify(newData));
      // 导航到成功页面
      this.$router.push('/succeed');

    }
  }
};
</script>